Skip to content

gh-142518: Annotate PyDict_* C APIs for thread safety#145875

Open
lysnikolaou wants to merge 2 commits intopython:mainfrom
lysnikolaou:annotate-pydict
Open

gh-142518: Annotate PyDict_* C APIs for thread safety#145875
lysnikolaou wants to merge 2 commits intopython:mainfrom
lysnikolaou:annotate-pydict

Conversation

@lysnikolaou
Copy link
Member

@lysnikolaou lysnikolaou commented Mar 12, 2026

Comment on lines +110 to +115
In the :term:`free-threaded build`, key hashing via
:meth:`~object.__hash__` and key comparison via :meth:`~object.__eq__`
can execute arbitrary Python code, during which the :term:`per-object
lock` may be temporarily released. For built-in key types
(:class:`str`, :class:`int`, :class:`float`), the lock is not released
during comparison.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean for users?
Do they need external synchronization if the dict may contain arbitrary keys?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this just means that with arbitrary user defined objects, the operations cannot be considered atomic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like it is atomic with built-in keys but shared with others?
It would be nice to use the same terminology as in the annotations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants